using MetaContainer;
using NUnit.Framework;
using Rhino.Mocks;

namespace Tests.MetaContainer
{
   [TestFixture]
   public class ExtensionMethodsTest
   {
      private MockRepository _mocks;

      [SetUp]
      public void SetUp()
      {
         _mocks = new MockRepository();
      }

      [Test]
      public void RegisterWithoutName()
      {
         IMetaContainer container = _mocks.CreateMock<IMetaContainer>();
         using (_mocks.Record())
         {
            container.Register(typeof(ITestInterface), typeof(SampleTestImpl), null);
         }

         using (_mocks.Playback())
         {
            container.Register(typeof(ITestInterface), typeof(SampleTestImpl));
         }
      }

      [Test]
      public void RegisterGenericWithName()
      {
         IMetaContainer container = _mocks.CreateMock<IMetaContainer>();
         using (_mocks.Record())
         {
            container.Register(typeof(ITestInterface), typeof(SampleTestImpl), null);
         }

         using (_mocks.Playback())
         {
            container.Register(typeof(ITestInterface), typeof(SampleTestImpl));
         }
      }

      [Test]
      public void GenericFactoryMethodRegistrationIsForwardedToNonGenericOne()
      {
         IMetaContainer container = _mocks.CreateMock<IMetaContainer>();
         using (_mocks.Record())
         {                                    
            container.Register(typeof(ITestInterface), name => new SampleTestImpl(), Scope.Transient);
            LastCall.IgnoreArguments();
         }

         using (_mocks.Playback())
         {            
            container.Register<ITestInterface>(name => new SampleTestImpl());            
         }
      }
   }
}
